<?php // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<?php 
$db =& JFactory::getDbo();
$query = $db->getQuery(true);
if (preg_match("/votre-profil\/.*-.*/", $_SERVER['REQUEST_URI'])){
	$uidtoshow=preg_replace('/.*votre-profil\/(.*)-.*/', '$1', $_SERVER['REQUEST_URI']);
	$user =& JFactory::getUser($uidtoshow);
} elseif (preg_match("/profil\/.*-.*/", $_SERVER['REQUEST_URI'])) {
	$uidtoshow=preg_replace('/.*profil\/(.*)-.*/', '$1', $_SERVER['REQUEST_URI']);
	$user =& JFactory::getUser($uidtoshow);
} else  {
		$user =& JFactory::getUser();
} 
	
echo "<h1> Les Tanks de ".$user->username."</h1>";
$db =& JFactory::getDbo();
$query = $db->getQuery(true);
$query="SELECT * FROM `#__wotclan_user` where `uid`='".$user->id."'";
//echo $query;
$db->setQuery($query);
$db->query();
$num_rows = $db->getNumRows();
$rows = $db->loadObjectList();
echo "<div align='right'>Accompte : <form><select name='account'>";
$accompte=explode('|',$rows[0]->account);
$y=0;
while ( $accompte[$y] != "" ) {
	$query2[$y] = $db->getQuery(true);
	$query2[$y]="SELECT * FROM `#__wotclan_account` where `uniqid`='".$accompte[$y]."'";
	
	$db->setQuery($query2[$y]);
	$db->query();
	$num_rows2 = $db->getNumRows();
	$rows2 = $db->loadObjectList();
	$x=0;
	while ($rows2[$x] != ""){
		echo "<option value='".$rows2[$x]->uniqid."'> ".$rows2[$x]->name."</option>";
		$x++;
  }
$y++;
}
echo "</select></form></div>";
//echo $query2[0];
echo "<div align='center'>";
//foreach ( $rows as $row ) {
	$account=$rows[0]->account;
	
	$query3 = $db->getQuery(true);
	
	$query3="SELECT * FROM `#__wotclan_account` where `uniqid`='".$accompte[0]."'";
	$db->setQuery($query3);
	$db->query();
	$num_rows3 = $db->getNumRows();
	$rows3 = $db->loadObjectList();
	
  foreach ( $rows3 as $row3 ) {
  	echo "<table><tr>";
    
    
    
    		
    $tank = explode("|",$row3->tanks);
        //echo $row->tanks."<br>";
    $x=0;
    $y=4;		
    while ($tank[$x] != ""){
    	$query4 = $db->getQuery(true);
    	$query4="SELECT * FROM `#__wotclan_tanks` WHERE `uniqid`='".$tank[$x]."'";
      //echo "<br>".$query2."<br>";
    	$db->setQuery($query4);
      $db->query();
      $num_rows4 = $db->getNumRows();
      $rows4 = $db->loadObjectList();
       
      if ($num_rows4 == 1){
        	  	
      			  //echo "tanks : ";
      	foreach ( $rows4 as $row4 ) {
      		echo "<td width='250' align='center' style='border:1px solid white'>";
      		$tabletank=explode(':',$row4->name);
      		    //$tabletank[0]=$row2->name);
      		if ($tabletank[0] == "france"){
      			echo "<img src='../../../media/mod_languages/images/fr.gif'> ";
      		}	else if ($tabletank[0] == "germany"){
      			echo "<img src='../../../media/mod_languages/images/de.gif'> ";
      		}	else if ($tabletank[0] == "ussr"){
      			echo "<img src='../../../media/mod_languages/images/ru.gif'> ";
      		}	else if ($tabletank[0] == "china"){
      			echo "<img src='../../../media/mod_languages/images/tr.gif'> ";
      		}	else if ($tabletank[0] == "uk"){
      			echo "<img src='../../../media/mod_languages/images/en.gif'> ";
      		}	else if ($tabletank[0] == "usa"){
      			echo "<img src='../../../media/mod_languages/images/us.gif'> ";
      		}	else {
      			echo $tabletank[0]." "; 
      		}
      		  
      		echo $tabletank[1]."</td>";
    		}
    			    
                    
                
      } elseif ($num_rows4 == 0) {
      	echo "<tr>Prob avec le tank ".$x."(".$tank[$x].") : aucun tank</tr>";
      } else {
      	echo "<tr>Prob avec le tank ".$x."(".$tank[$x].") : trop de tank</tr>";
      }
        
        
		$x++;
		if ($x == $y){
			echo "</tr><tr>";
			$y=$y+4;
		}
    		
  	}
  }
  echo "</tr></table>";
  	 
	
echo "<br><a href= '/index.php/component/wotclan/'>Ajouter un replay</a> d'un de vos tanks pour l'ajouter</div>";
    

 ?>